<?php
class My_member extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		// 登录校验
		$this->common->check_login_admin ();
		$this->load->helper ( array (
				'form',
				'url' 
		) );
	}
	
	/**
	 * 我的会员
	 */
	public function index() {
		$this->load->model ( 'user_model' );
		
		if(empty($_POST['search'])){
			// $result = $this->user_model->member_list ();
			//$data['member_list'] = $this->get_member_list($this->user_info['user_account']);//$member_lsit;

			$data ['my_users'] = $this->get_member_list('dedaozhe');//$member_lsit;

			
		}else{
			$result = $this->user_model->member_list_one ( $_POST['search'] );
			//var_dump($result);
			if(!empty($result)){
				$lv=array('1'=>'得道者','2'=>'天时','3'=>'地利','4'=>'人和','5'=>'君子');
				foreach ($result as $k => $v) {
					$this->user->get_member_list_up($result[$k]['user_account']);
					
					$result[$k]['tj_num'] = count($this->user->get_member_list_up($result[$k]['user_account']));
				
					$result[$k]['tlv']=$lv[$result[$k]['team_lv']];
				}
				
			}
			

			$data ['my_users'] = $result;
			
		}
		
		$this->db->where('kick_status', '0');
		$this->db->from('pc_ddth_user');
		$total = $this->db->count_all_results();
		
		$data['usercount']=$total;

		$this->db->where('kick_status', '0');
		$this->db->where('create_time >', strtotime(date('Y-m-d')));
		$this->db->from('pc_ddth_user');
		$newtotal = $this->db->count_all_results();
		
		$data['newusercount']=$newtotal;
		
		$data ['left'] = $this->load->view ( 'admin/left', '', TRUE );

		$data ['menu'] = $this->load->view ( 'admin/menu', '', TRUE );
		
		$this->load->view ( 'admin/my_member', $data, FALSE );
	}

	public function ajax_get_member_list(){
		$acc = $_POST['acc'];

		if(!$acc){
			echo 0;exit;
		}
		$a = $this->get_member_list($acc);
		
		//echo json_encode($a);exit;
		header('Content-Type:application/json; charset=utf-8');

        exit(json_encode($a));
	}

	/**
	 * 获取用户列表
	 */
	private function get_member_list($acc)
	{
		$member_lsit = $this->user->get_member_list_up($acc);

		$lv=array('1'=>'得道者','2'=>'天时','3'=>'地利','4'=>'人和','5'=>'君子');

		foreach ($member_lsit as $k => $v)
		{
			$num = count($this->user->get_member_list_up($v['user_account']));

			$member_lsit[$k]['tj_num'] = $num;
			$member_lsit[$k]['tlv']=$lv[$v['team_lv']];
		}

		return $member_lsit;
	}
}